package com.aaa.tars.controller;

import com.aaa.tars.entity.Ticket;
import com.aaa.tars.service.TicketService;
import com.aaa.tars.util.Page;
import com.aaa.tars.util.Result;
import com.aaa.tars.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @FileName: TicketController
 * @Description: 门票控制层
 * @Author: 李宗盛
 * @CreateTime: 2025/9/12 11:14
 * @Version: 17
 */
@RestController
@RequestMapping("/ticket")
public class TicketController {
    @Resource
    private TicketService ticketService;
    // 新增：查询某景区下所有门票
    @GetMapping("queryByScenicId")
    public Result queryByScenicId(Integer scenicId) {
        return ResultUtil.success(ticketService.queryByScenicId(scenicId));
    }

    // 新增：查询门票及下属所有订单（关联查询接口）
    @GetMapping("queryWithOrders")
    public Result queryTicketWithOrders(Integer ticketId){
        return ResultUtil.success(ticketService.queryTicketWithOrders(ticketId));
    }
    
    @PostMapping("queryByPage")
    public Result queryByPage(@RequestBody Page<Ticket> page) {
        return ResultUtil.success(ticketService.queryByPage(page));
    }


    @GetMapping("queryById")
    public Result queryById(Integer ticketId) {
        return ResultUtil.success(ticketService.queryById(ticketId));
    }
    
    @PostMapping("add")
    public Result add(@RequestBody Ticket ticket) {

        return ResultUtil.success(ticketService.add(ticket));
    }
    
    @PostMapping("update")
    public Result update(@RequestBody Ticket ticket) {
        return ResultUtil.success(ticketService.update(ticket));
    }
    
    @DeleteMapping("deleteById")
    public Result deleteById(Integer ticketId) {
        return ResultUtil.success(ticketService.deleteById(ticketId));
    }
}